daphnia = read.table("V:/My Documents/ENT420/lab/data95.dat", sep="\t",
header=T)

symbols(daphnia$x,daphnia$y,circles=log(daphnia$area), inches=.2)

color = ifelse(daphnia$now==1, "red", "white")

symbols(daphnia$x, daphnia$y, circles=log(daphnia$area), inches=.2, bg
= color)

plot(daphnia$area, daphnia$now, log="x")


daphnia$larea = log(daphnia$area)

fit = glm(now ~ larea, family = binomial(), data = daphnia)

summary(fit)

fit$coef

exp(fit$coef[1])

exp(fit$coef[2])


exp(fit$coef[1]+2*fit$coef[2])

a=fit$coef[1]
b=fit$coef[2]

p.fun=function(x){
exp(a+b*x)/(1 + exp(a+b*x))
}
curve(p.fun, to=0, from=10, add=T)

expsub = daphnia$past==1
expdata = daphnia[expsub,] #subset the data

colsub = daphnia$past==0
coldata = daphnia[colsub,] #subset the data

#(a) To study extinction, plot presence/absence against log-area using the expdata data-set.
	plot(expdata$larea, expdata$now)
	curve(p.fun,0,10,add=T)

#(b) Do a logistic regression using the expdata. How does extinction depend on area?
#(c) Use curve() to superimpose the logistic model for extinction on the plot?
#(d) To study colonization, plot presence/absence against log-area using the coldata data-set.
#(e) Do a logistic regression using the coldata. How does colonization depend on area?
#(f) Use curve() to superimpose the logistic model for colonization on the plot?
#Page 4
